import { serializeOptions } from '../../utils/util'
import { setTitle } from '../../utils/wxapi'
Component({
	properties: {
		type: {
			type: Number,
			value: 1
		},
		title: {
			type: String,
			value: '出错了'
		},
		msg: {
			type: String,
			value: ''
		}
	},
	data: {},
	methods: {
		// 刷新
		refresh() {
			const pages = getCurrentPages()
			console.log(pages)
			if (pages.length > 0) {
				const { route, options } = pages[pages.length - 1]
				const optionsStr = serializeOptions(options)
				wx.reLaunch({
					url: `/${route}?${optionsStr}`
				})
			} else {
				wx.reLaunch({
					url: '/pages/home/index'
				})
			}
		},
		// 返回上级
		back() {
			wx.navigateBack({
				delta: 1
			})
		},
		// 重启
		reLaunch() {
			wx.reLaunch({
				url: '/pages/home/index'
			})
		},
		// 返回首页
		backHome() {
			wx.reLaunch({
				url: '/pages/home/index'
			})
		}
	},
	attached() {
		setTitle(this.data.title)
		console.log(this.data)
	}
})
